package com.atguigu.datastream.test.day04;

import org.apache.flink.api.common.serialization.SimpleStringSchema;
import org.apache.flink.streaming.api.datastream.DataStreamSink;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.apache.flink.streaming.api.functions.sink.filesystem.StreamingFileSink;
import org.apache.flink.streaming.connectors.kafka.FlinkKafkaProducer;

/**
 * ClassName: Flink_02_Sink_kafka
 * Package: com.atguigu.test.day04
 * Description:
 *
 * @Author ChenJun
 * @Create 2023/4/10 21:08
 * @Version 1.0
 */
public class Flink_02_Sink_kafka {
    public static void main(String[] args) throws Exception {

        //1. 创建流的执行环境
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();

        env.setParallelism(1);

        //2. 获取数据
        DataStreamSource<String> streamSource = env.socketTextStream("localhost", 9999);

        // TODO 3.将数据写入kafka
        streamSource.addSink(new FlinkKafkaProducer<String>("hadoop102:9092", "first", new SimpleStringSchema()));

        env.execute();

    }
}
